package com.example.demo.controller;

import com.example.demo.utils.Reservation;
import com.example.demo.utils.RenewalReservationRequest;
import com.example.demo.service.ReservationService;
import com.example.demo.utils.ApiResponse;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ReservationController {

    @Autowired
    private ReservationService reservationService;

    @GetMapping("/Reservation/StoreID/{storeId}/From/{date}")
    public ApiResponse getReservation(@PathVariable String storeId, @PathVariable String date) {
        return reservationService.getReservation(storeId, date);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "Token for authentication", required = true, dataType = "string", paramType = "header")
    })
    @PostMapping("/api/Reservation")
    public synchronized ApiResponse checkReservation(@RequestHeader("token") String token, @RequestBody Reservation reservation) {
        return reservationService.checkReservation(token, reservation);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "Token for authentication", required = true, dataType = "string", paramType = "header")
    })
    @PostMapping("/api/Reservation/Renew")
    public synchronized ApiResponse renewReservation(@RequestHeader("token") String token, @RequestBody RenewalReservationRequest renewalReservationRequest) {
        return reservationService.renewReservation(token, renewalReservationRequest);
    }
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "Token for authentication", required = true, dataType = "string", paramType = "header")
    })
    @DeleteMapping("/api/Reservation/{ReservationID}")
    public synchronized ApiResponse cancelReservation(@RequestHeader("token") String token,@PathVariable String ReservationID){
        return reservationService.cancelReservation(token,ReservationID);
    }
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "Token for authentication", required = true, dataType = "string", paramType = "header")
    })
    @GetMapping("/api/Reservation")
    public ApiResponse getUserReservation(@RequestHeader("token")String token){
        return  reservationService.getUserReservation(token);
    }

}
